home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
276-300
/
291
/
keyboard
/
keyboard.doc
< prev
next >
Wrap
Text File
|
1995-03-14
|
6KB
|
133 lines
KEYBOARD.C--Translating Inutition RAWKEY Class Messages into Useful Codes
by Fabbian G. Dufoe, III
INTRODUCTION
Getting ordinary keystrokes into your program is a tricky business on
the Amiga if you want to use Intuition's windows and other features.
Intuition provides two IDCMP flags: VANILLAKEY and RAWKEY. VANILLAKEY
returns ASCII codes for the standard ASCII characters but doesn't tell you
anything about functions keys, cursor keys, or the help key. RAWKEY
identifies the physical key which was pressed buy you have to do some extra
processing to relate it to the key value assigned to it in the user's
keymap. Keyboard.c does that extra processing for you. This document
explains how to call the three functions to open the console device, close
the console device, and get ASCII keycodes or unique key identifiers from
the console device.
This document and the other files in this archive are in the public
domain. You may use them any way you wish.
FILES IN THIS ARCHIVE
This archive contains the following files:
Keyboard.c Source code for functions to translate RAWKEY Intuition
messages to usable keycodes
Keyboard.doc Documentation for Keyboard.c
Keyboard.h Function prototypes and declarations for programs using
Keyboard.c
Keyboard.o Object file compiled from Keyboard.c with the Lattice
AmigaDOS C compiler, version 5.02. You can use this as
a link-time library if you have a compiler that uses the
standard Amiga object format.
RawDemo Executable demonstration program that uses the
Keyboard.c functions
RawDemo.c Source code for Keyboard.c demonstration program
RawDemo.lmk Input for the Lattice lmk utility for compiling
RawDemo.c and Keyboard.c
QUICK INSTRUCTIONS
To use the functions in Keyboard.c you must include Keyboard.h in your
source file (#include "Keyboard.h"). If your C compiler does not support
function prototypes define the symbolic constant "__NOPROTO" in your source
file (#define __NOPROTO).
Open the console device by calling OpenReadConsole(). OpenReadConsole()
takes no arguments. It returns 0 if it succeeds or -1 if it fails.
When you get an Intuition RAWKEY class message call ReadKey() to decode it.
You have to set the IDCMP RAWKEY flag when you open your window to get
RAWKEY class messages. ReadKey() requires three arguments.
1. A pointer to the Intuition message (struct IntuiMessage *)
2. A pointer to the key ID number (unsigned short int *)
3. A pointer to the keymap (struct KeyMap *)
To use the default keymap set the pointer to NULL.
ReadKey() returns a char. If the key can be represented by a standard ASCII
character ReadKey() will return that character. Note that control
characters are included in this category. ReadKey() returns 0 for keys
which can't be represented by an ASCII character. In that case the key can
be identified by the value in the KeyID field. The value will match one of
the symbolic constants defined in Keyboard.h. If ReadKey() fails it returns
-1. If the message was not a RAWKEY class message or if it was a "key up"
message ReadKey() returns -2. You can safely ignore return values of -2.
Close the console device by calling CloseReadConsole(). CloseReadConsole()
takes no arguments and returns nothing.
THEORY
The console device (like all Amiga devices) is also a library. It provides
a function called RawKeyConvert() which translates Intuition RAWKEY messages
into the sequences you would get if you were reading the console device
directly. RawKeyConvert would generate 0x9b 0x30 0x7e if you pressed the F1
key.
To use RawKeyConvert() you need a pointer to the console device just as you
need a pointer to the Intuition library to use any Intuition functions.
OpenReadConsole() calls the exec function OpenDevice with a unit number of
-1. That gets a pointer to the device library vector without opening an
actual console. You need to get the pointer before you call ReadKey()
because ReadKey() uses RawKeyConvert().
If you want to write to the console device you'll have to call OpenDevice()
directly. That's beyond the scope of this document. You'll need to look in
the ROM Kernel Manual: Libraries and Devices for discussion of the console
device (chapter 8), the ROM Kernel Manual: Exec for discussion of messages
and ports (chapter 3) and input and output (chapter 4), and the Autodocs for
information about OpenDevice (Autodocs1.3/DevicesA-K/console.doc).
ReadKey() passes the Intuition message along to DeadKeyConvert() which calls
RawKeyConvert(). DeadKeyConvert is taken substantially from the 1.2
Enhancer manual (page 65). Dead keys allow you to add diacritical marks to
some characters. On the usa keymap there are five dead keys: F, G, H, J,
and K. If you hold down the ALT key and press F nothing happens. That's
why it's called a dead key. Now press e. There will be an accent mark
above the e (i).
RawKeyConvert() doesn't know about dead keys, so you need to use
DeadKeyConvert() as a front end. Both RawKeyConvert() and DeadKeyConver()
place a sequence of codes in a buffer. The sequence can vary in length.
ASCII characters require a single code. Function keys may require four.
ReadKey() parses the sequences returned by DeadKeyConvert() and reduces
everything to a single code. Printable characters (and control characters)
are returned to the caller. It identifies special keys by placing a code in
the KeyID field pointed to by the caller. The caller does not have to
examine the KeyID field unless ReadKey() returns 0.
DOCUMENTATION OF FUNCTIONS
The interface parameters for each function in Keyboard.c are included as
comments in the source code.